//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.tool.custom.gallery;

import android.content.Context;
import android.graphics.Camera;
import android.graphics.Matrix;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Transformation;
import android.widget.Gallery;
import android.widget.ImageView;

public class CReflectionGallery extends Gallery {
    private Camera mCamera = new Camera();
    private int mMaxRotationAngle = 60;
    private int mMaxZoom = -120;
    private int mCoverflowCenter;

    public CReflectionGallery(Context context) {
        super(context);
        this.setStaticTransformationsEnabled(true);
    }

    public CReflectionGallery(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.setStaticTransformationsEnabled(true);
    }

    public CReflectionGallery(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.setStaticTransformationsEnabled(true);
    }

    public int getMaxRotationAngle() {
        return this.mMaxRotationAngle;
    }

    public void setMaxRotationAngle(int maxRotationAngle) {
        this.mMaxRotationAngle = maxRotationAngle;
    }

    public int getMaxZoom() {
        return this.mMaxZoom;
    }

    public void setMaxZoom(int maxZoom) {
        this.mMaxZoom = maxZoom;
    }

    private int getCenterOfCoverflow() {
        return (this.getWidth() - this.getPaddingLeft() - this.getPaddingRight()) / 2 + this.getPaddingLeft();
    }

    private static int getCenterOfView(View view) {
        return view.getLeft() + view.getWidth() / 2;
    }

    protected boolean getChildStaticTransformation(View child, Transformation t) {
        int childCenter = getCenterOfView(child);
        int childWidth = child.getWidth();
        t.clear();
        t.setTransformationType(Transformation.TYPE_MATRIX);
        if(childCenter == this.mCoverflowCenter) {
            this.transformImageBitmap((ImageView)child, t, 0);
        } else {
            int rotationAngle = (int)((float)(this.mCoverflowCenter - childCenter) / (float)childWidth * (float)this.mMaxRotationAngle);
            if(Math.abs(rotationAngle) > this.mMaxRotationAngle) {
                rotationAngle = rotationAngle < 0?-this.mMaxRotationAngle:this.mMaxRotationAngle;
            }

            this.transformImageBitmap((ImageView)child, t, rotationAngle);
        }

        return true;
    }

    private void transformImageBitmap(ImageView child, Transformation t, int rotationAngle) {
        this.mCamera.save();
        Matrix imageMatrix = t.getMatrix();
        int imageHeight = child.getLayoutParams().height;
        int imageWidth = child.getLayoutParams().width;
        int rotation = Math.abs(rotationAngle);
        this.mCamera.translate(0.0F, 0.0F, 100.0F);
        if(rotation < this.mMaxRotationAngle) {
            float zoomAmount = (float)((double)this.mMaxZoom + (double)rotation * 1.5D);
            this.mCamera.translate(0.0F, 0.0F, zoomAmount);
        }

        this.mCamera.rotateY((float)rotationAngle);
        this.mCamera.getMatrix(imageMatrix);
        imageMatrix.preTranslate((float)(-(imageWidth / 2)), (float)(-(imageHeight / 2)));
        imageMatrix.postTranslate((float)(imageWidth / 2), (float)(imageHeight / 2));
        this.mCamera.restore();
    }

    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        this.mCoverflowCenter = this.getCenterOfCoverflow();
        super.onSizeChanged(w, h, oldw, oldh);
    }
}
